package com.meepo.basic

import com.meepo.basic.schema.Session
import com.meepo.basic.schema.user.User
import com.meepo.basic.schema.common.ResponseWrapper
import com.meepo.basic.upgrader.AppUpgrade
import com.meepo.sdk.component.http.RetrofitManager
import io.reactivex.Observable
import retrofit2.http.GET
import retrofit2.http.POST
import retrofit2.http.Query

/**
 * @author
 *
 * @date  2020/10/27 11:11 PM
 * @version 1.0
 */
internal interface API {

    companion object {
        private var sInstance: API? = null

        fun get(): API {
            if (sInstance == null)
                sInstance = RetrofitManager.create(
                    API::class.java, null
                )
            return sInstance as API
        }
    }


    @GET("/api/v1/app/settings")
    fun fetchAppSettings(): Observable<ResponseWrapper<Session.AppSettings>>

    @GET("/api/v1/app/upgrade")
    fun fetchUpgradeInfo(): Observable<ResponseWrapper<AppUpgrade>>

    @POST("/api/v1/auth/sms_codes")
    fun sendCode(@Query("phoneNo") phoneNo: String): Observable<ResponseWrapper<Any>>

    @POST("/api/v1/auth/sms-login")
    fun loginByCode(@Query("phoneNo") phoneNo: String, @Query("code") code: String): Observable<ResponseWrapper<User>>

    @POST("/api/v1/auth/pw-login")
    fun loginByPassword(@Query("phoneNo") phoneNo: String, @Query("password") password: String): Observable<ResponseWrapper<User>>

    @POST("/api/v1/auth/one-key-login")
    fun loginByOneKey(@Query("accessToken") accessToken: String): Observable<ResponseWrapper<User>>
}